import Vue from "vue";
import Vuex from "vuex";
import { setter } from "./vuex";
console.log(setter,'setter===7878')
import { creatSocket,getUrlParams } from "../script/utils";
const { userId } = getUrlParams();
Vue.use(Vuex);
const setState = (commit, path, reducer) => {
  commit("set", { path, reducer });
};
const store = new Vuex.Store({
  state: {
    msgPush: "",
    choicenessMessage: "",
  },
  plugins: [],
  mutations: { set: setter },
  actions: {
    pushMsgMessage({ state, commit }) {
      const uId = userId || window.localStorage.getItem("userId");
      const key = `0_7_${uId}_2`; //私信推送
      creatSocket(key, function(data) {
        console.log(key);
        console.log("Msg>>>>", data.broadcasting_interaction);
        // setState(commit, "msgPush", data.broadcasting_interaction);
      });
    },
    //精选推送
    pushChoicenessMessage({ state, commit }) {
      const key = `0_9_0_2`;
      creatSocket(key, function(data) {
        console.log("Msg>>>>", data);
        setState(commit, "choicenessMessage", data);
      });
    },
  },
});
export default store;
store.dispatch("pushMsgMessage");
store.dispatch("pushChoicenessMessage");
